package mdt;

import java.io.*;

public class PandocCompiler
{
	static void Compile(String _inputFile, String _outputFile, String _options) throws CompilerException
	{		
		Process pr;
		
		try
		{
			Runtime rt = Runtime.getRuntime();
			String command = String.format(Configuration.CompilerCommand + _options, _inputFile, _outputFile);
			pr = rt.exec(command);	
			
			int exitVal = pr.waitFor();
			
			if (exitVal != 0)
			{
				BufferedReader input = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
				String message = input.readLine();
				throw new CompilerException(message, null);
			}
		}
		catch (InterruptedException e)
		{
			throw new CompilerException(e.getMessage(), e);
		}
		catch (IOException e)
		{
			throw new CompilerException(e.getMessage(), e);
		}
	}
}
